Page({
  data: {
    info: {
      "CustomerDemandId": null, 
      "CustomerContactId": null, 
      "CustomerId": null, 
      "PersonName": "",
      "ContactTypeId": null, 
      "Direction": null, 
      "ContactContent": "", 
      "ContactResult": "", 
      "NextContactTime": "" 
    }
  },
  onLoad(e) {
    var newinfo = this.data.info
    newinfo.CustomerId = e.id
    newinfo.CustomerDemandId = e.did
    this.setData({info: newinfo})
  },
  changeValue(e){
    var aftdata = this.data.info
    if(e.target.dataset.parent){
      aftdata[e.target.dataset.parent][e.target.dataset.key] = e.detail.value
    }else{
      aftdata[e.target.dataset.key] = e.detail.value
    }
    this.setData({info:aftdata})
  },
  closeboard() {
    dd.hideKeyboard();
  },
  openboard(e) {
    var _this = this
    setTimeout(() => {
      _this.setData({focus:e.target.dataset.key})
    }, 100);
  },
  toSlt(e) {
    console.log(e);
    var str = "?"
    for (const i in e.target.dataset) {
      str+= i+"="+e.target.dataset[i]+"&"
    }
    str = str.substr(0,str.length-1)
    if(str.length <= 1){
      return;
    }
    dd.navigateTo({
      url: "/pages/marks/sltradio/sltradio" + str
    })
  },
  toSltContact() {
    dd.navigateTo({
      url: "./contactslt/contactslt?id=" + this.data.info.CustomerId
    })
  },
  timeSlt(e) {
    var newinfo = this.data.info
    var keyname = e.target.dataset.name
    var _this = this
    dd.datePicker({
      format: 'yyyy-MM-dd HH:mm',
      currentDate: newinfo[keyname],
      success: (res) => {
        newinfo[keyname] = res.date
        _this.setData({info: newinfo})
      },
    });
  },
  save() {
    console.log(this.data.info);
    var info = this.data.info
    if(!info.CustomerContactId){
      dd.showToast({
        type: 'fail',
        content: '必须选择一个联系人'
      });
      return;
    }
    if(!info.ContactContent){
      dd.showToast({
        type: 'fail',
        content: '联系内容不能为空'
      });
      return;
    }
    getApp().req({
      url: "/customer/contactrecord/add",
      type: "POST",
      data: info,
      cb(res){
        dd.navigateBack()
      }
    })
  }
});
